package com.lyouu.dataminer.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.lyouu.dataminer.db.DbConstants;
import com.lyouu.dataminer.factory.MysqlDbFactory;

public class MdMembersDao {
	public String getUsernameByUid(int uid) throws SQLException {
		String username = "";
		Connection conn = MysqlDbFactory.getConnection(DbConstants.DB_LYOUU);
		String sql = "SELECT username FROM md_members WHERE uid=?";
		PreparedStatement stmt = conn.prepareStatement(sql);
		stmt.setInt(1, uid);
		ResultSet rs = stmt.executeQuery();
		while (rs.next()) {
			username = rs.getString(1);
		}
		rs.close();
		conn.close();
		return username;
	}

	public int getUidByUsername(String username) throws SQLException {
		int uid = 0;
		Connection conn = MysqlDbFactory.getConnection(DbConstants.DB_LYOUU);
		String sql = "SELECT uid FROM md_members WHERE username=?";
		PreparedStatement stmt = conn.prepareStatement(sql);
		stmt.setString(1, username);
		ResultSet rs = stmt.executeQuery();
		while (rs.next()) {
			uid = rs.getInt(1);
		}
		rs.close();
		conn.close();
		return uid;
	}
	
}
